<?php
/** .-------------------------------------------------------------------
 * |  Software: [HDCMS framework]
 * |      Site: www.hdcms.com
 * |-------------------------------------------------------------------
 * |    Author: 向军 <2300071698@qq.com>
 * |    WeChat: aihoudun
 * | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
 * '-------------------------------------------------------------------*/

namespace web\admin\controller;


/**
 * Class Link
 * 友情链接
 */

class Link extends Common{
    //动作
	protected $db;
	public function __construct()
	{
		parent::__construct();
		$this->db = new \system\model\Link();
	}
//    显示模板
	public function index(){
		$data = $this->db->get();
		View::with('data',$data)->make();
	}
//    添加
	public function add(){
		if(IS_POST)
		{   //如果添加成功
			if($this->db->store())
			{
				message('添加成功',u('index'),'success');
			}
			//如果添加失败，提示错误信息
			message($this->db->getError(),'','error');
		}
		View::make();
	}
//    编辑
    public function edit(){
//        获取旧数据
        if (IS_POST){
            if ($this->db->edit()){
                message('修改成功',u('index'),'success');
            }
            message($this->db->getError(),'','error');
        }
        $lid = q('get.lid',0,'intval');
        $oldData =$this->db->where('lid',$lid)->first();
        View::with('oldData',$oldData)->make();
    }
    //删除
    public function del(){
        $lid = q('get.lid',0,'intval');
        $this->db->where('lid',$lid)->delete();
        message('删除成功',u('index'),"success");
    }
}
